package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.vo.album.AlbumCategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	/**
	 * 获取基础分类列表
	 *
	 * @return 包含基础分类列表的Result对象
	 */
	@Operation(summary = "查询所有分类列表") // 定义操作的概要描述
	@GetMapping("/getBaseCategoryList") // 映射GET请求到/getBaseCategoryList路径
	public Result<List<AlbumCategoryVo>> getBaseCategoryList() {

		// 调用baseCategoryService的getBaseCategoryList方法获取基础分类列表
		List<AlbumCategoryVo> categoryList = baseCategoryService.getBaseCategoryList();

		// 返回包含基础分类列表的Result对象
		return Result.ok(categoryList);
	}

	/**
	 * 根据id查询专辑属性
	 *
	 * @param category1Id 一级分类id，必需参数
	 * @return 包含查询到的专辑属性列表的Result对象
	 */
	@Operation(summary = "根据id查询专辑属性")
	@GetMapping("/findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> findAttribute(
			// 定义路径变量category1Id，并标记为必需参数
			@Parameter(name="category1Id", description = "一级分类id", required = true)
			@PathVariable(value = "category1Id") Long category1Id
	){
		// 调用baseCategoryService的findAttribute方法，传入category1Id作为参数，获取专辑属性列表
		List<BaseAttribute> attributeList = baseCategoryService.findAttributeByCategory1Id(category1Id);

		// 构造并返回包含查询结果的Result对象
		return Result.ok(attributeList);
	}

	@Operation(summary = "根据三级分类id查询专辑分类信息")
	@GetMapping("/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> findCategoryInfoBy3Id(@PathVariable(value = "category3Id") Long category3Id){

		BaseCategoryView baseCategoryView = baseCategoryService.findCategoryInfoBy3Id(category3Id);
		return Result.ok(baseCategoryView);

	}


}

